package com.wantup.remote.client;

import java.io.DataOutputStream;
import java.net.Socket;

/**
 * 基于RPC的远程关机等CMD命令控制
 *
 * @author wangshangyi
 * @version V1.0  2020/8/14 16:23
 */
public class RPCClient {

    String s = null;

    Socket mysocket;


    DataOutputStream out = null;


    RPCClient() {
        try {
            mysocket = new Socket("192.168.0.106", 8888);
//下面是初始化流
            out = new DataOutputStream(mysocket.getOutputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) {
        RPCClient server = new RPCClient();
        server.sendOrder("mmc");//打开对方的控制台
        try {
            Thread.sleep(500);
        } catch (Exception e) {
            e.printStackTrace();
        }/*发送命令的时候注意延时的控制、否则会做过命令*/
//        server.sendOrder("shutdown -s -t 200");// 让对方在200秒内关机
        server.sendOrder("shutdown -r");// 重启电脑
        try {
            Thread.sleep(500);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        server.sendOrder("shutdown -a");//取消关机
    }


    public void sendOrder(String s) {
        try {
            out.writeUTF(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
